package com.gary.BoneCP;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import com.jolbox.bonecp.BoneCP;
import com.jolbox.bonecp.BoneCPConfig;
import com.jolbox.bonecp.BoneCPDataSource;

public class bonecp_2 {
	public static void main(String[] args) {
		BoneCP connectionPool = null;
		Connection connection = null;
		Statement stmt=null;
		ResultSet rs=null;

		try {
			// 加载数据库驱动
			try {
				Class.forName("com.mysql.jdbc.Driver");
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
			// 创建一个DataSource对象
			BoneCPDataSource ds = new BoneCPDataSource();
			// 设置JDBC URL
			ds.setJdbcUrl("jdbc:mysql://localhost:3306/breaks");
			// 设置用户名
			ds.setUsername("root");
			// 设置密码
			ds.setPassword("");
			// 下面的代码是设置其它可选属性
			// ds.setXXXX(...);
			
			connection = ds.getConnection();

			if (connection != null) {
				System.out.println("Connection successful!");
				stmt = connection.createStatement();
				rs = stmt.executeQuery("SELECT * FROM user");
				while (rs.next()) {
					System.out.println(rs.getInt(1) + ":"
							+ rs.getString("user_name"));
				}
			}
			// 关闭数据库连接池
			//connectionPool.shutdown();
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			if (connection != null) {
				try {
					rs.close();
					connection.close();
					stmt.close();
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}
}